package mornd.bootstart;

import lombok.ToString;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author: mornd
 * @dateTime: 2023/5/24 - 14:57
 */

@ToString
@Component
public class User implements BeanNameAware, ApplicationContextAware, InitializingBean {
    public User() {
        System.out.println("user()");
    }

    String name;

    @Value("张三")
    public void setName( String name) {
        this.name = name;
        System.out.println("@Value 方法");
    }

    @Autowired
    public void foo() {
        System.out.println("foo()");
    }

    @PostConstruct
    public void init() {
        System.out.println("init()");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("setBeanName() name=" + name);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet...");

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext...");
    }
}
